﻿package  
{
	import com.junkbyte.console.Cc;	
	
	import Interface.Common.XYZArrows;
	
	import Gameplay.Battlefield;
	import Gameplay.Water.WaterPlane;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageDisplayState;		
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;	
	import flash.events.Event;	
	
	public class Demo extends Sprite 
	{
		private var FWater:WaterPlane;
		private var FBattleField:Battlefield;
		private var FIce:IceCorners;
		private var FXYZ:XYZArrows;	
			
		public function Demo():void
		{
			//Stage settings
			super.stage.scaleMode = StageScaleMode.NO_SCALE;
			super.stage.align = StageAlign.TOP_LEFT;
			//Inintializing console
			SetupConsole();			
			//Interface setup
			FIce = getChildByName('Exterier') as IceCorners;			
			FXYZ = getChildByName('XYZHelper') as XYZArrows;
			FWater = new WaterPlane();			
			FBattleField = new Battlefield();
			addChild(FWater);			
			swapChildren(FIce, FWater);			
			addChild(FBattleField);
			swapChildren(FIce, FXYZ);
			
			addEventListener(Event.ADDED_TO_STAGE, OnAddedToStage);			
			
			Cc.addSlashCommand('omitFrames', FWater.OmitFrames, 'Setting a count of frames that will be omitted in water rendering cycle');
		}
		
		private function OnAddedToStage(e:Event):void 
		{			
			removeEventListener(Event.ADDED_TO_STAGE, OnAddedToStage);			
			stage.addEventListener(Event.RESIZE, OnStageResize);
		}
		
		private function OnStageResize(e:Event):void 
		{
			Cc.width = stage.stageWidth;
		}
		
		private function Fullscreen():void
		{
			if(stage.displayState == StageDisplayState.NORMAL)
				stage.displayState = StageDisplayState.FULL_SCREEN;
			else
				stage.displayState = StageDisplayState.NORMAL;
		}
		
		private function SetupConsole():void
		{				
			Cc.config.style.backgroundAlpha = 0.8;			
			Cc.startOnStage(this, '`');
			Cc.width = stage.stageWidth;
			Cc.fpsMonitor = true;			
			Cc.memoryMonitor = true;
			Cc.commandLine = true;
			Cc.config.commandLineAllowed = true;
			Cc.config.style.topMenu = false;
			Cc.addSlashCommand('fs', Fullscreen, 'Switches between fullscreen and normal modes');			
			Cc.visible = true;
		}		
	}
}